// https://umijs.org/config/
import { defineConfig } from 'umi';
import { join } from 'path';
import defaultSettings from './defaultSettings';
import proxy from './proxy';

const { REACT_APP_ENV } = process.env;

export default defineConfig({
  hash: true,
  antd: {},
  dva: {
    hmr: true,
  },
  layout: {
    // https://umijs.org/zh-CN/plugins/plugin-layout
    locale: true,
    siderWidth: 208,
    ...defaultSettings,
  },
  // https://umijs.org/zh-CN/plugins/plugin-locale
  locale: {
    // default zh-CN
    default: 'zh-CN',
    antd: true,
    // default true, when it is true, will use `navigator.language` overwrite default
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@ant-design/pro-layout/es/PageLoading',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
  /**
   *  配合后台返回的动态菜单，此处做静态映射
   *  在pages写好逻辑后，需要在此处写路由（一定要写全，不能只写在后台）
   *  此处集合了react写的所有page的组件，所有的view路由
   *  后台再根据权限处理，返回动态路由，展示到用户前台
   */

  /** 系统设置路由 */
  routes: [
    // 首页，导航
    {
      path: "/",
      layout: false,
      component: './HomeNav'
    },
    // 社交登录跳转界面
    {
      path: '/autoLogin',
      layout: false,
      routes: [
        // 默认跳转登录页面
        // {
        //   path: '/autoLogin',
        //   redirect: '/user/login',
        // },
        // 1，钉钉登录
        {
          path: '/autoLogin/dingTalk',
          name: 'autoLogin-dingtalk',
          layout: false,
          component: './User/Login/components/DingTalkLogin',
        },
      ],
    },

    // 登录界面
    {
      path: '/login',
      name: "login",
      layout: false,
      component: './User/Login',
    },

    // 用户钉钉扫码登录界面（测试）
    {
      path: '/login/dingTalk',
      layout: false,
      name: 'login',
      component: './User/Login/dingTalk',
    },

    // 首次登录，强制修改密码界面
    {
      name: 'user-first-login',
      layout: false,
      path: '/user/firstLogin',
      component: './User/Login/FirstLogin',
    },

    // 系统管理页面
    {
      path: '/user',
      layout: true,
      routes: [
        // 当访问模块主路径时，默认跳转页面
        {
          path: '/user',
          redirect: '/user/account/settings',
        },
        // 用户设置（右上角用户菜单）
        {
          name: 'user-settings',
          layout: true,
          path: '/user/account/settings',
          component: './User/Account/settings',
        },
      ],
    },

    // 首页

    // 收入记账
    {
      name: 'income',
      layout: true,
      path: '/income',
      component: './Income',
    },

    // 支出记账
    {
      name: 'payment',
      layout: true,
      path: '/payment',
      component: './Payment',
    },

    // 借出记账
    {
      name: 'lend',
      layout: true,
      path: '/lend',
      component: './Lend',
    },

    // 借入记账
    {
      name: 'owe',
      layout: true,
      path: '/owe',
      component: './Owe',
    },

    // 收入流水
    {
      name: 'incomeLogs',
      layout: true,
      path: '/logs/income',
      component: './IncomeLogs',
    },

    // 支出流水
    {
      name: 'paymentLogs',
      layout: true,
      path: '/logs/payment',
      component: './PaymentLogs',
    },

    // 借钱流水
    {
      name: 'lendLogs',
      layout: true,
      path: '/logs/lend',
      component: './LendLogs',
    },

    // 欠债流水
    {
      name: 'OweLogs',
      layout: true,
      path: '/logs/owe',
      component: './OweLogs',
    },
    // 404页
    {
      path: '*',
      layout: true,
      component: './404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': defaultSettings.primaryColor,
  },
  // esbuild is father build tools
  // https://umijs.org/plugins/plugin-esbuild
  esbuild: {},
  title: false,
  ignoreMomentLocale: true,
  proxy: proxy[REACT_APP_ENV || 'dev'],
  manifest: {
    basePath: '/',
  },
  // Fast Refresh 热更新
  fastRefresh: {},
  openAPI: [
    {
      requestLibPath: "import { request } from 'umi'",
      // 或者使用在线的版本
      // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
      schemaPath: join(__dirname, 'oneapi.json'),
      mock: false,
    },
    {
      requestLibPath: "import { request } from 'umi'",
      schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
      projectName: 'swagger',
    },
  ],
  nodeModulesTransform: {
    type: 'none',
  },
  mfsu: {},
  webpack5: {},
  exportStatic: {},
});
